package com.ruoyi.lvlian.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.lvlian.dto.LhsOrderItemDto;
import com.ruoyi.lvlian.vo.LhsOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.lvlian.domain.LhsOrderItem;
import com.ruoyi.lvlian.service.ILhsOrderItemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 莱回收订单项Controller
 *
 * @author ruoyi
 * @date 2025-07-23
 */
@Api(value = "莱回收-订单项", tags = "莱回收订单项Controller")
@RestController
@RequestMapping("/lhsOrderItem")
public class LhsOrderItemController extends BaseController {
    @Autowired
    private ILhsOrderItemService lhsOrderItemService;

    /**
     * 查询莱回收订单项列表
     */
//    @RequiresPermissions("lvlian:lhsOrderItem:list")
    @GetMapping("/list")
    public TableDataInfo list(LhsOrderItemDto lhsOrderItem) {
        startPage();
        List<LhsOrderItem> list = lhsOrderItemService.selectLhsOrderItemList(lhsOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出莱回收订单项列表
     */
//    @RequiresPermissions("lvlian:lhsOrderItem:export")
/*    @Log(title = "莱回收订单项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LhsOrderItem lhsOrderItem) {
        List<LhsOrderItem> list = lhsOrderItemService.selectLhsOrderItemList(lhsOrderItem);
        ExcelUtil<LhsOrderItem> util = new ExcelUtil<LhsOrderItem>(LhsOrderItem.class);
        util.exportExcel(response, list, "莱回收订单项数据");
    }*/

    /**
     * 获取莱回收订单项详细信息
     */
//    @RequiresPermissions("lvlian:lhsOrderItem:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(lhsOrderItemService.selectLhsOrderItemById(id));
    }


    /**
     * 修改莱回收订单项
     */
//    @RequiresPermissions("lvlian:lhsOrderItem:edit")
    @Log(title = "莱回收订单项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LhsOrderItem lhsOrderItem) {
        return success(lhsOrderItemService.updateLhsOrderItem(lhsOrderItem));
    }


    @PostMapping("/remove")
    @Log(title = "删除莱回收订单项", businessType = BusinessType.DELETE)
    public AjaxResult remove(@RequestBody String[] ids) {
        if (ids == null || ids.length == 0) {
            return error("未选中");
        }
        int i = lhsOrderItemService.deleteLhsOrderItemByIds(ids);
        if (i > 0) {
            return success("删除成功");
        }
        return toAjax(i);
    }

    @Log(title = "莱回收订单项批量添加", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult addBatch(@RequestBody List<LhsOrderItem> lhsOrderItems) {
        List<String> ids = new ArrayList<>();
        try {
            ids = lhsOrderItemService.batchInsertLhsOrderItem(lhsOrderItems);
        } catch (Exception e) {

            e.printStackTrace();
            return error("保存失败");

        }

        return success(ids);
    }


}
